import Vue from 'vue'
import Vuex from 'vuex'

// 导入让vuex持久化的插件
import createPersistedstate from 'vuex-persistedstate'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: ''
  },
  mutations: {
    setToken(state, token) {
      state.token = token
    },
    removeToken(state) {
      state.token = ''
    }
  },
  actions: {
    async actionSetToken(store, token) {
      await store.commit('setToken', token)
    },
    logoutAction(store) {
      store.commit('removeToken')
    }
  },
  getters: {
  },
  modules: {
  },
  plugins: [
    // 让数据在vuex中存储的同时在localStorage中也存一份
    createPersistedstate({
      key: 'bigEvent'
    })
  ]
})
